    package sasp_KML;
// KMLgen is a class that is responisble for outputing the coordinates to a file
// google earth can read. This class is implementation specific and could be replaced
// with a different mapping GUI program.

import sasp_protocol.Entity;
import sasp_protocol.Protocol;
import java.io.IOException;
import java.util.*;
import org.boehn.kmlframework.kml.Document;
import org.boehn.kmlframework.kml.Camera;
import org.boehn.kmlframework.kml.Kml;
import org.boehn.kmlframework.kml.KmlException;
import org.boehn.kmlframework.kml.Placemark;
import saspmanager.SASPManagerView;

public class KMLgen {
HashSet<Entity> group;
Entity self;
Protocol protocol1;
SASPManagerView S;

// Constructor establishes reffernce variables to both the protocol class
// and the self class
public KMLgen(Protocol protocol, Entity you){
	group = protocol.getgroup1();
        protocol1 = protocol;
        self = you;
}
// passes a refference to the GUI so the entity list refreashes with the map
public void setview(SASPManagerView _S){
    S= _S;
}
// rewrites the KML file
public synchronized void write() throws IOException, KmlException {
		
		// We add a document to the kml
		
		Kml kml = new Kml();
		Document document = new Document();
		kml.setFeature(document);
		
                
                Camera camera = new Camera();
		camera.setLatitude(39.954096);
                camera.setLongitude(-75.166397);
                camera.setAltitude(2000.00);

                Placemark place = new Placemark();
                
                // We add the placemarks to the Document
		
                group = protocol1.getgroup1();
		saspmanager.SASPManagerApp.addLine("group has "+ group.toString());
                for (Entity one: group){
			 one.go();
			document.addFeature(one.mark);
		}
                saspmanager.SASPManagerApp.addLine("KML - Map Rewriten");
		self.go();
                document.addFeature(self.mark);
		
		// We generate the kml file
		kml.createKml("Ifi.kml");

                // We Update the entity list in the GUI
                S.updatelist();
		
		
	}

}
